<template>
  <div>

    <div class="flrc">
      <div class="flex1"></div>
      <div>
        <mu-button small flat color="primary">选择</mu-button>
        <mu-button small flat color="primary">新建</mu-button>
      </div>
    </div>
    <mu-row style="width: 100%" class="bdtso">
      <mu-data-table style="width: 100%" @select-change="updates" selectable
                     select-all :selects.sync="selects" checkbox :columns="columns" :data="list">
        <div slot="th">请选择后操作</div>
        <template slot-scope="scope">
          <td>
            <table-row-creator ref="form" :form.sync="scope.row" :items.sync="items" :openEdit="true" labelPosition="top"></table-row-creator>
          </td>
        </template>
      </mu-data-table>
    </mu-row>
  </div>
</template>

<script>
import api from '@/assets/js/api'
import TableRowCreator from '../FormCreator/Creator/TableRowCreator'

export default {
  name: 'sons',
  components:{TableRowCreator},
  props: {
    val: '',
    entityName: '',
    multi: ''
  },
  data () {
    return {
      selects: [],
      columns: ['val'],
      list: [],
      items:{}
    }
  },
  methods: {
    getData () {
      let _this = this
      api.post('/admin/' + _this.entityName + '/listForm', {val: this.val}, function (res) {
        if (res.s*1 === 1) {
          _this.list = res.d.list
          _this.items = res.d.form
        }
      })
    },
    updates (index, selects) {
      let _this = this
      let data = []
      console.log(selects)
      console.log(index)
      this.selects.map(function (d) {
        data.push(_this.list[d].id)
      })
      console.log(data)
      this.$emit('change', data)
    }
  },
  created () {
  },
  mounted () {
    this.getData()
  },
  watch: {
    selects () {
      this.updates()
    }
  }
}
</script>

<style scoped>

</style>
